package com.huiyeji.dynamic.core;

import java.util.List;

/**
 * @author Huiyeji
 */
public abstract class DynamicExtendFactory extends DynamicObjectFactory {

    private final GlobalBeanRegistry registry = new GlobalBeanRegistry();

    public DynamicExtendFactory(List<DynamicObject> dynamicObjects) {
        super(dynamicObjects);
        extend(registry);
        globalRegister();
    }

    private void globalRegister(){
        for (DynamicObject dynamicObject : registry.dynamicObjects) {
            _register(dynamicObject,true);
        }
    }

    public void globalRegister(Object object){
        _register(DynamicBuilderManager.Anno.build(object),true);
    }

    public void globalRegister(String name, Object object){
        DynamicObject dynamicObject = DynamicBuilderManager.Anno.build(object);
        dynamicObject.setDynamicObjectName(name);
        _register(dynamicObject,true);
    }

    public void globalRegister(DynamicObject dynamicObject){
        _register(dynamicObject,true);
    }

    protected abstract void extend(GlobalBeanRegistry registry);
}
